package com.wjh.controller;


import com.wjh.pojo.User;
import com.wjh.service.AnnualListingsService;
import com.wjh.service.TablenameService;
import com.wjh.service.UserService;
import com.wjh.utils.ResponseResult;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

@RestController
@RequestMapping("system")
public class StudioUserController {

    @Resource
    private UserService userService;

    @Resource
    private AnnualListingsService annualListingsService;

    @Resource
    private TablenameService tablenameService;

    @GetMapping("/queryAll")
    public ResponseResult queryAll(Integer pageNum,Integer pageSize,
                                   Integer type,Integer headNumber,Integer tagId,String headClass){
        return userService.queryAll(pageNum,pageSize,type,headNumber,tagId,headClass);
    }

    @GetMapping("/list/annual")
    public ResponseResult queryAnnual(){
        return ResponseResult.okResult(annualListingsService.list());
    }

    @GetMapping("/list/tablenam")
    public ResponseResult queryTabName(){
        return ResponseResult.okResult(tablenameService.list());
    }

    @GetMapping("/user/introduction")
    public ResponseResult getIntroduction(){
        return userService.getIntroduction();
    }

    @PutMapping("/user/update")
    public ResponseResult update(@RequestBody User user){
        return userService.updateUser(user);
    }

    /**
     * 导出所有工作室用户信息
     * */
    @PreAuthorize("@ps.hasPermission('content:category:export')")
    @GetMapping("/user/export")
    public ResponseResult export(HttpServletResponse response){
        return userService.export(response);
    }

    /**
     * 删除工作室成员
     * */
    @DeleteMapping("/user/{id}")
    public ResponseResult deleteUser(@PathVariable("id")List<Integer> ids){
        return userService.deleteUser(ids);
    }

    @PutMapping("/user/changeStatus")
    public ResponseResult changeStatus(@RequestBody User user){
        return userService.changeStatus(user);
    }

    /**
     * 添加用户(由于软测需要，暂时为Put，后续改为POst)
     */
    @PostMapping("/user")
    public ResponseResult addUser(@RequestBody User user){
        return userService.addUser(user);
    }

}
